package com.longnuoqi.mydoctor.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.yunhe.mydoctor.R;

import java.util.List;
import java.util.Map;

public class ZizhenGridAdapter extends BaseAdapter{
    private List<Map<String,Object>> list;
    private Context context;
    private LayoutInflater inflater;
    public ZizhenGridAdapter(Context context, List<Map<String, Object>> list){
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.zizhen_gridview_item,null);
            holder.img = (ImageView) convertView.findViewById(R.id.doctor_gridview_img);
            holder.text = (TextView) convertView.findViewById(R.id.doctor_gridview_text);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.img.setImageResource((Integer) (list.get(position).get("img")));
        holder.text.setText((String)(list.get(position).get("name")));
        return convertView;
    }
    private class ViewHolder{
        public ImageView img;
        public TextView text;
    }
}
